<?php 

class MetricsController extends BackendAppController
{
	var $name = 'Metrics';
	var $uses = array();
	var $helpers = array('Html', 'Form', 'Cms.Ajax');
	
	function admin_get()
	{
		$this->layout = 'ajax';
		Configure::write('debug', 0);
		App::import('Vendor', 'Cms.GigaMetrics');
		$allMetrics = array();
		$models = Utility::getBehaviorIndex('Cms.Metric');
		if(!empty($models))
		{
			foreach($models as $model)
			{
				$modelName = Utility::getFieldName($model);
				if(strpos($modelName, 'Cms') === 0)
				{
					continue; // we dont want abstract models here
				}
				$metrics = GigaMetricsFetcher::getData($model, 'all');
				if(!$metrics)
				{
					continue;
				}
				foreach($metrics as $key => $metric)
				{
					$allMetrics[] = $metric;
				}
			}
		}
		
		$jsonArr = array();
		foreach($allMetrics as $metric)
		{
			$jsonArr[] = $metric->get();
		}
		$this->set('metrics', $jsonArr); // later to be used as ajax req.
	}
}

?>